capture log close

clear
drop _all
set more off

*	Use Stata's date function to define today's date. Define the
*		date in the following format: YYYYMMDD.
*;
	local todaysdate: display %tdCCYYNNDD date(c(current_date), "DMY")	
			
	*	Display the date.
	*;
		display `todaysdate'	

*	Use Stata's date function to define time the code is being run. 
*		Define the date in the following format: YYYYMMDD.
*;
	local currentime: display %tcHHMM clock(c(current_time), "hms")	
			
	*	Display the date.
	*;
		display `currentime'
			
*	Save the date 
*;
	global filename "`todaysdate' `currentime'" 
	display "$filename"

*	Filenames
*;
	global data "location_of_data_and_code\paperfigs"
	global output "location_of_data_and_code\paperfigs"

*	Code has been anonomyized to plot the average as 570 rather than that
*		reported by R in the non-anonomyized code. As the figure notes in the
*		paper state: "the average funds per renting household [is] about $570."
*;

*	Do the scatter plots
*;
	*	Poverty
	*;
		*	Load the data created by era_analysis_clean.R
		*;
			use "$data\pov_renthh.dta", clear
	
		*	Convert from a decimal to a percentage
		*;
			gen double pov_rate = pov * 100
		
		*	Create a max minus min difference to put in the graph
		*;
			quietly sum avg_fundsperrenthh	if	bin == 10 
			scalar decile10 = r(sum)
			
			quietly sum avg_fundsperrenthh	if	bin == 1 
			scalar decile1 = r(sum)
			
			scalar diff = 25*ceil((decile10 - decile1)/25) 
			display diff
			
		*	Create the graph
		*;
			#delimit ;
			graph twoway scatter avg_fundsperrenthh pov_rate
				, 	graphregion(color(white)) bgcolor(white)
					ytitle("Funds Per Renting Household")
					xtitle("Poverty Rate (%)")
					yline(570, lcolor(black) lpattern(dash))	
					ylabel(0(200)1000, nogrid)
					xlabel(,nogrid)
					text(100 22 "Difference between highest and lowest decile {&cong} $`=diff'")
					plotregion(m(b=0 l=0))
					mcolor(black)
					
					name(graph_pov, replace)
					scale(1.4)
					;
			#delimit cr
			
			*	Export the graphs
			*;
				graph export "$output\pov_updated_$filename.eps", replace
				
	*	Race - Black
	*;
		*	Load the data created by era_analysis_clean.R
		*;
			use "$data\black_renters.dta", clear

		*	Convert from a decimal to a percentage
		*;
			gen double race_rate = perblack * 100
		
		*	Create a max minus min difference to put in the graph
		*;
			quietly sum avg_fundsperrenthh	if	bin == 10 
			scalar decile10 = r(sum)
			
			quietly sum avg_fundsperrenthh	if	bin == 1 
			scalar decile1 = r(sum)
			
			scalar diff = 25*ceil((decile10 - decile1)/25) 
			display diff
			
		*	Create the graph
		*;
			#delimit ;
			graph twoway scatter avg_fundsperrenthh race_rate
				, 	graphregion(color(white)) bgcolor(white)
					ytitle("Funds Per Renting Household")
					xtitle("% Renting Householder is Black")
					yline(570, lcolor(black) lpattern(dash))
					ylabel(0(200)1000, nogrid)
					xlabel(,nogrid)
					text(100 40 "Difference between highest and lowest decile {&cong} $`=diff'") 
					legend(off)
					plotregion(m(b=0 l=0))
					mcolor(black)
					
					name(graph_race_black, replace)
					scale(1.4)
					;
			#delimit cr
			
			*	Export the graphs
			*;
				graph export "$output\race_black_renter_updated_$filename.eps", replace

	*	Race - Hispanic
	*;
		*	Load the data created by era_analysis_clean.R
		*;
			use "$data\hispanic_renters.dta", clear

		*	Convert from a decimal to a percentage
		*;
			gen double race_rate = perhisp * 100
		
		*	Create a max minus min difference to put in the graph
		*;
			quietly sum avg_fundsperrenthh	if	bin == 10 
			scalar decile10 = r(sum)
			
			quietly sum avg_fundsperrenthh	if	bin == 1 
			scalar decile1 = r(sum)
			
			scalar diff = 25*ceil((decile10 - decile1)/25) 
			display diff
			
		*	Create the graph
		*;
			#delimit ;
			graph twoway scatter avg_fundsperrenthh race_rate
				, 	graphregion(color(white)) bgcolor(white)
					ytitle("Funds Per Renting Household")
					xtitle("% Renting Householder is Hispanic")
					yline(570, lcolor(black) lpattern(dash))
					ylabel(0(200)1000, nogrid)
					xlabel(,nogrid)
					text(100 40 "Difference between highest and lowest decile {&cong} $`=diff'")  
					legend(off)
					plotregion(m(b=0 l=0))
					mcolor(black)
					
					name(graph_race_hisp, replace)
					scale(1.4)
					;
			#delimit cr	
			
			*	Export the graphs
			*;
				graph export "$output\race_hisp_renter_updated_$filename.eps", replace
				
	*	Renters with Kids
	*;
		*	Load the data created by era_analysis_clean.R
		*;
			use "$data\rent_w_kids.dta", clear
		
		*	Convert from a decimal to a percentage
		*;
			gen double renterswithkids_rate = renthh_wkidsunder18 * 100
		
		*	Create a max minus min difference to put in the graph
		*;
			quietly sum avg_fundsperrenthh	if	bin == 10 
			scalar decile10 = r(sum)
			
			quietly sum avg_fundsperrenthh	if	bin == 1 
			scalar decile1 = r(sum)
			
			scalar diff = 25*ceil((decile10 - decile1)/25) 
			display diff
			
		*	Create the graph
		*;
			#delimit ;
			graph twoway scatter avg_fundsperrenthh renterswithkids_rate 
				, 	graphregion(color(white)) bgcolor(white)
					ytitle("Funds Per Renting Household")
					xtitle("% Renting Households with Kids")
					yline(570, lcolor(black) lpattern(dash))
					ylabel(0(200)1000, nogrid)
					xlabel(,nogrid)
					text(100 35 "Difference between highest and lowest decile {&cong} $`=diff'") 
					legend(off)
					plotregion(m(b=0 l=0))
					mcolor(black)
					
					name(graph_rentinghhswithkids, replace)
					scale(1.4)
					;
			#delimit cr
			
			*	Export the graphs
			*;
				graph export "$output\rentinghhswithkids_updated_$filename.eps", replace

	*	Renters that are single moms
	*;
		*	Load the data created by era_analysis_clean.R
		*;
			use "$data\singlemom.dta", clear

		*	Convert from a decimal to a percentage
		*;
			gen double renterssinglemoms_rate = renthh_singlemomwkids * 100
		
		*	Create a max minus min difference to put in the graph
		*;
			quietly sum avg_fundsperrenthh	if	bin == 10 
			scalar decile10 = r(sum)
			
			quietly sum avg_fundsperrenthh	if	bin == 1 
			scalar decile1 = r(sum)
			
			scalar diff = 25*ceil((decile10 - decile1)/25) 
			display diff
			
		*	Create the graph
		*;
			#delimit ;
			graph twoway scatter avg_fundsperrenthh renterssinglemoms_rate 
				, 	graphregion(color(white)) bgcolor(white)
					ytitle("Funds Per Renting Household")
					xtitle("% Renting Households Headed by Single Mothers")
					yline(570, lcolor(black) lpattern(dash))
					ylabel(0(200)1000, nogrid)
					xlabel(,nogrid)
					text(100 20 "Difference between highest and lowest decile {&cong} $`=diff'") 
					legend(off)
					plotregion(m(b=0 l=0))
					mcolor(black)
					
					name(graph_rentingsinglemoms, replace)
					scale(1.4)
					;
			#delimit cr
			
			*	Export the graphs
			*;
				graph export "$output\rentsinglemoms_updated_$filename.eps", replace
	
	*	Evictions
	*;
		*	Load the data created by era_analysis_clean.R
		*;
			use "$data\eviction.dta", clear
			
		*	Convert from a decimal to a percentage
		*;
			gen double eviction_rate_perrenthh = evic_per_renthh * 100
		
		*	Create a max minus min difference to put in the graph
		*;
			quietly sum fundsperrenthh	if	evicbin == 10 
			scalar decile10 = r(sum)
			
			quietly sum fundsperrenthh	if	evicbin == 1 
			scalar decile1 = r(sum)
			
			scalar diff = 25*ceil((decile10 - decile1)/25) 
			display diff
			
		*	Create the graph
		*;
			#delimit ;
			graph twoway scatter fundsperrenthh eviction_rate
				, 	graphregion(color(white)) bgcolor(white)
					ytitle("Funds Per Renting Household")
					xtitle("Annual Eviction Filings per 100 Renting Households, 2015-2018")
					yline(570, lcolor(black) lpattern(dash))
					ylabel(0(200)1000, nogrid)
					xlabel(, nogrid)
					text(100 17 "Difference between highest and lowest decile {&cong} $`=diff'") 
					legend(off)
					plotregion(m(b=0 l=0))
					mcolor(black)
					
					scale(1.4)
					name(graph_evictions, replace)
					;
			#delimit cr
			
			*	Export the graphs
			*;
				graph export "$output\evictions_$filename.eps", replace
		
	*	Rent Burden
	*;
		*	Load the data created by era_analysis_clean.R
		*;
			use "$data\rentburden.dta", clear
		
		*	Create a max minus min difference to put in the graph
		*;
			quietly sum avg_fundsperrenthh	if	bin == 10 
			scalar decile10 = r(sum)
			
			quietly sum avg_fundsperrenthh	if	bin == 1 
			scalar decile1 = r(sum)
			
			scalar diff = 25*ceil((decile10 - decile1)/25) 
			display diff
			
		*	Create the graph
		*;
			#delimit ;
			graph twoway scatter avg_fundsperrenthh rentburden
				, 	graphregion(color(white)) bgcolor(white)
					ytitle("Funds Per Renting Household")
					xtitle("Rent as a % of Income")
					yline(570, lcolor(black) lpattern(dash))
					ylabel(0(200)1000, nogrid)
					xlabel(,nogrid)
					text(100 35 "Difference between highest and lowest decile {&cong} $`=diff'") 
					legend(off)
					plotregion(m(b=0 l=0))
					mcolor(black)
					
					name(graph_rentburden, replace)
					scale(1.4)
					;
			#delimit cr
			
			*	Export the graphs
			*;
				graph export "$output\rentburden_$filename.eps", replace	
		
	*	Risk Rank
	*;
		*	Load the data
		*;
			use "$data\rank_weighted.dta", clear
	
		*	Create a max minus min difference to put in the graph
		*;
			quietly sum avg_fundsperrenthh	if	bin == 10 
			scalar decile10 = r(sum)
			
			quietly sum avg_fundsperrenthh	if	bin == 1 
			scalar decile1 = r(sum)
			
			scalar diff = 25*ceil((decile10 - decile1)/25) 
			display diff
			
		*	Create the graph
		*;
			#delimit ;
			graph twoway scatter avg_fundsperrenthh bin
				, 	graphregion(color(white)) bgcolor(white)
					ytitle("Funds Per Renting Household")
					xtitle("Index Decile")
					yline(570, lcolor(black) lpattern(dash))	
					ylabel(0(200)1000, nogrid)
					xlabel(, nogrid)
					text(100 50 "Difference between highest and lowest decile {&cong} $`=diff'")
					plotregion(m(b=0 l=0))
					mcolor(black)
					
					scale(1.4)
					name(graph_rank, replace)
					;
			#delimit cr
			
			*	Export the graphs
			*;
				graph export "$output\rank_weighted_$filename.eps", replace
				
				